function logTime(index) {

	var times = JSON.parse(localStorage.getItem('times'));
	if (times == null) {
		times = [];
	}

	var now = new Date().getTime();
	var page_load_time = now - performance.timing.navigationStart;
	console.log("User-perceived page loading time: " + page_load_time);

	times[index - 1] = page_load_time;

	localStorage['times'] = JSON.stringify(times);

}

function onLoad() {

	if (Modernizr.localstorage) {
		console.log('storage ok');
		var count = localStorage.getItem("count");
		if (count != null) {
			count++;
			if (count <= 5) {
				logTime(count);
				location.reload();
			} else {
				count = 0;
				console.log(localStorage['times']);
				var times = JSON.parse(localStorage['times']);
				var total = 0;

				for ( var i = 0; i < times.length; i++) {
					console.log(times[i]);
					total += parseInt(times[i]);
				}
				total = total / times.length;
				console.log('average: ' + total);
				localStorage.removeItem('times');
			}
		} else {
			count = 0;
			logTime(count);
		}
		localStorage.setItem("count", count);
	} else {
		console.log('storage not available ok');
	}

}

function loadScripts(){
	console.log('loadScripts');

	var scripts = document.getElementsByTagName('script');
	console.log(scripts.length);
	console.log(scripts);
	var scriptIndex = 0;
	for (var i = 0; i< scripts.length; i++){
		var scriptEl = scripts[i]	;
		if(scriptEl.type=='notJs'){
			scriptEl.type = 'text/javascript';
			scriptEl.parentNode.removeChild(scriptEl);
			document.body.appendChild(scriptEl);
		}else{
			scriptIndex++;
		}
	}
	
	
}
